home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / gedeiffel / tools / eiffel / arexx / execute.rexx < prev    next >
OS/2 REXX Batch file  |  1999-11-29  |  4KB  |  152 lines

  1. /****** execute.rexx *******************************************************
  2.  * NAME
  3.  *    execute.rexx -- Execute command in console.
  4.  * USAGE
  5.  *    rx execute.rexx command
  6.  * FUNCTION
  7.  *    Execute `command' in console opened by console.rexx
  8.  *
  9.  *    Before the actual command is executed, the console is made to change
  10.  *    change its internal current directory to the same where this script was
  11.  *    started from. If this directories are not equal upon invocation, the
  12.  *    EiffelShell also displays this CD command.
  13.  * RESULT
  14.  *    The return code of the command executed by the console or 10 if
  15.  *    the console is not running. In the later case, you also get a
  16.  *    descriptive error message.
  17.  * EXAMPLES
  18.  *    A simple invocation can be:
  19.  *
  20.  *       rx execute.rexx echo sepp
  21.  *
  22.  *    If you want to do sophisticated things like redirection, you have
  23.  *    to quote the whole command, e.g.
  24.  *
  25.  *       rx execute.rexx "echo sepp >t:sepp.text"
  26.  *
  27.  *    if you want to use quotes and redirection, you have to escape them
  28.  *    as usually
  29.  *
  30.  *       rx execute.rexx "echo *"sepp was here*" >t:sepp.text"
  31.  *
  32.  *    results in the command
  33.  *
  34.  *       echo "sepp was here" >t:sepp.text
  35.  *
  36.  *    to be executed.
  37.  * COPYRIGHT
  38.  *    Copyright (C) 1999 Thomas Aglassinger <agi@sbox.tu-graz.ac.at>
  39.  *    Freeware. Use at your own risk.
  40.  * SEE ALSO
  41.  *    console.rexx
  42.  ***************************************************************************/
  43. version_info = "$VER: execute.rexx 1.1 (17.1.99)"
  44.  
  45. Options Results
  46.  
  47. Signal On Failure
  48. Signal On NoValue
  49.  
  50. template = 'Port/K,Command/A/F'
  51. port = 'CONSOLE.1'
  52.  
  53. console_script = "golded:tools/eiffel/arexx/console.rexx"
  54.  
  55. Call add_library('rexxdossupport.library', 2, '')
  56.  
  57. /* Check Arguments */
  58. Parse Arg arguments
  59.  
  60. If Strip(arguments, 'B', ' "') = '?' then do
  61.    Call WriteCh('STDOUT', template || ': ')
  62.    Pull arguments
  63. end
  64.  
  65. if ~ReadArgs(arguments, template) then do
  66.    Say "Error in arguments: " || Fault(RC)
  67.    Exit 10
  68. end
  69.  
  70. if ~Show('Ports', port) then do
  71.    console_specification = GetVar('Console/' || port)
  72.    if RC ~= 0 then do
  73.       console_specification = ,
  74.          'CON:0/9999/512/84/' || port || ,
  75.          '/AUTO/CLOSE/INACTIVE/ALT0/9999/512/400/SCREEN**'
  76.    end
  77.  
  78.    console_command = 'run <>nil: rx >"' || console_specification || '" ' || ,
  79.                      console_script || ' Port="' || port || '"'
  80.                      
  81.    Address Command console_command
  82.    if RC = 0 then do
  83.       Address Command 'WaitForPort ' || port
  84.    end
  85.    else do
  86.       Say 'Attempt to start new console at port "' || port || '" failed.'
  87.       Say '(The console script is expected to be in "' || console_script || '".)'
  88.    end
  89. end
  90.  
  91. /* Do it */
  92. if Show('Ports', port) then do
  93.    Address Value port
  94.    'cd-internal "' || Pragma('Directory') || '"'
  95.    command
  96.    Exit RC
  97. end
  98. else do
  99.    Say 'Can not find output console at port "' || port || '"'
  100.    Say 'Start console.rexx before using this script'
  101.    Exit 10
  102. end
  103.  
  104. /* Signal handler for CLI failures */
  105. Failure:
  106.    Say 'Command failed return code ' || RC
  107.    Exit RC
  108.  
  109. /* Signal handler for accessing unitialized variables */
  110. NoValue:
  111.    LF = d2c(10)
  112.    message = LF || SIGL SourceLine(SIGL) || LF || ,
  113.              'uninitialized value in line ' || SIGL
  114.    Say message
  115.    Exit 20
  116.  
  117. /****** ugly/add_library **************************************************
  118.  * NAME
  119.  *   add_library -- Add library or abort.
  120.  * FUNCTION
  121.  *   If the requested library exists in "libs:", it is opened AddLib().
  122.  *
  123.  *   Otherwise, `message', prefixed by "Library ... not found.", is
  124.  *   displayed and the program exts with code 20.
  125.  * INPUTS
  126.  *   library - Name of the library to open
  127.  *   version - Minimum library version (0 for any)
  128.  * RESULT
  129.  *   If this function returns, everything was ok.
  130.  **************************************************************************/
  131. add_library: procedure
  132.     Parse Arg library, version, error_message
  133.  
  134.     if ~Show('L', library) then do
  135.         added = 0
  136.         if Exists('libs:' || library) then do
  137.            added = AddLib(library, 0, -30, version)
  138.         end
  139.         if ~added then do
  140.             message = "Library '" || library "'"
  141.             if (version > 0) then do
  142.                 message = message || " version " || version
  143.             end
  144.             message = message || 'not found. ' || error_message
  145.             Say message
  146.             Exit 20
  147.         end
  148.     end
  149.  
  150.     return
  151.  
  152.